﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using System.Data;
using System.Web.Services;
namespace AirPlane
{
    public partial class ChiTietGopY : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["islogin"] == null || (bool)Session["islogin"] == false || Session["type"].ToString() == "3" || Session["type"].ToString() == "4" || Session["type"].ToString() == "5" || Session["type"].ToString() == "6")
            {

                Response.Redirect("TrangChu.aspx");
            }
            else
            {
                if (!IsPostBack && Request["id"] != null)
                {
                    fillData(Request["id"].ToString());
                }
            }

        }
        public void fillData(string ID)
        {
            DataTable dt = new DataTable();
            GopYBUS bus = new GopYBUS();
            dt = bus.layChiTietThongTinGopY(ID);
            if (dt.Rows.Count > 0)
            {
                lbChiTiet.Text = dt.Rows[0]["noiDung"].ToString();
                lbKhachHang.Text = dt.Rows[0]["hoTenKhachHang"].ToString();
                lbEmail.Text = dt.Rows[0]["email"].ToString();
            }
        }


        protected void btnReply_Click(object sender, EventArgs e)
        {
            if (Session["islogin"] == null || (bool)Session["islogin"] == false)
            { }
            else
            {
                DataTable dt = new DataTable();
                GopYBUS bus = new GopYBUS();

                int n = 0;

                string s1 = "";
                n = bus.capNhatGopY(Session["username"].ToString(), int.Parse(Request["id"].ToString()));
                if (n > 0)
                {
                    EmailBUS.sendMailGopY(lbEmail.Text, lbKhachHang.Text, editReply.Content);
                    s1 = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Đã Gửi Mail Cho Khách Hàng!.</span>";
                }
                else
                {
                    s1 = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Đã Có Lỗi Xảy Ra! Vui Lòng Thử Lại.</span>";
                }
                lbThongBao.Text = s1;
            }
        }

    }
}